package com.example.myapplication;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class Fragment1 extends Fragment {

    private RecyclerView recyclerView;// 定义RecyclerView变量，用于显示图片
    private Fragment1_ImageAdapter imageAdapter;// 定义ImageAdapter变量，用于管理RecyclerView中图片的展示
    private List<Fragment1_ImageItem> imageList;// 定义List变量，用于存储图片数据

    private RecyclerView recyclerViewButtons;// 定义另一个RecyclerView变量，用于显示按钮
    private Fragment1_ButtonAdapter buttonAdapter;// 定义ButtonAdapter变量，用于管理RecyclerView中按钮的展示
    private List<Fragment1_ButtonItem> buttonList;// 定义List变量，用于存储按钮数据

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_1, container, false);
        // 设置图片的 RecyclerView
        recyclerView = view.findViewById(R.id.recyclerViewImages);// 获取RecyclerView的引用
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));// 设置布局管理器为水平线性布局

        // 初始化图片数据
        imageList = new ArrayList<>();
        imageList.add(new Fragment1_ImageItem(R.drawable.miku1)); // 确保你有相应的图片资源
        imageList.add(new Fragment1_ImageItem(R.drawable.miku4));
        imageList.add(new Fragment1_ImageItem(R.drawable.miku3));
        // 添加更多图片...

        imageAdapter = new Fragment1_ImageAdapter(imageList);
        recyclerView.setAdapter(imageAdapter);

        // 设置按钮的 RecyclerView
        recyclerViewButtons = view.findViewById(R.id.recyclerViewButtons);
        recyclerViewButtons.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));

        // 初始化按钮数据
        buttonList = new ArrayList<>();
        buttonList.add(new Fragment1_ButtonItem("工具箱", Fragment1_Page1Activity.class));
        buttonList.add(new Fragment1_ButtonItem("时事趣闻", Fragment1_Page1Activity.class));
        buttonList.add(new Fragment1_ButtonItem("快速计算机", Fragment1_Page1Activity.class));
        buttonList.add(new Fragment1_ButtonItem("小组件", Fragment1_Page1Activity.class));
        buttonList.add(new Fragment1_ButtonItem("塞壬唱片", Fragment1_Page5Activity.class));
        // 添加更多按钮...

        buttonAdapter = new Fragment1_ButtonAdapter(getContext(), buttonList);// 创建ButtonAdapter对象，并将按钮数据传递给它
        recyclerViewButtons.setAdapter(buttonAdapter);// 将ButtonAdapter设置给RecyclerView


        return view;
    }
}